<html>
<head>
<meta charset="UTF-8">
<title>KBEngine - KBEngine cell</title>
<link href="../../style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td align=left style="background:#708090"> <font size=15 color=#ffffff> KBEngine </font></td></tr>
</table> <hr>
<h1>KBEngine module</h1>
This <a href="KBEngine.html">KBEngine</a> module provides 
the Python script access to the <a href="../Classes/Entity.html">entity</a>'s 
cell part, in particular it provides the registration and removal of timers, 
as well as the creation of <a href="../Classes/Entity.html">entities</a>.

<h2><a href="#" onClick="obj=document.getElementById( 'classes' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Classes</a></h2>
<table id="classes" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="class_list"><a href="../Classes/Entity.html" class="class_list" >Entity</a></span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'functions' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Member functions</a></h2>
<table id="functions" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#addSpaceGeometryMapping" class="function_list" >addSpaceGeometryMapping</a>( spaceID, mapper, path, shouldLoadOnServer, params ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#addWatcher" class="function_list" >addWatcher</a>( path, dataType, getFunction ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#address" class="function_list" >address</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#MemoryStream" class="function_list" >MemoryStream</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#createEntity" class="function_list" >createEntity</a>( entityType, spaceID, position, direction, params ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#debugTracing" class="function_list" >debugTracing</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#delSpaceData" class="function_list" >delSpaceData</a>( spaceID, key ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#delWatcher" class="function_list" >delWatcher</a>( path ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#deregisterReadFileDescriptor" class="function_list" >deregisterReadFileDescriptor</a>( fileDescriptor ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#deregisterWriteFileDescriptor" class="function_list" >deregisterWriteFileDescriptor</a>( fileDescriptor ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#executeRawDatabaseCommand" class="function_list" >executeRawDatabaseCommand</a>( command, callback, threadID, dbInterfaceName ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#genUUID64" class="function_list" >genUUID64</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getResFullPath" class="function_list" >getResFullPath</a>( res ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getSpaceData" class="function_list" >getSpaceData</a>( spaceID, key ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getSpaceGeometryMapping" class="function_list" >getSpaceGeometryMapping</a>( spaceID ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getWatcher" class="function_list" >getWatcher</a>( path ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getWatcherDir" class="function_list" >getWatcherDir</a>( path ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#getAppFlags" class="function_list" >getAppFlags</a>( ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#hasRes" class="function_list" >hasRes</a>( res ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#isShuttingDown" class="function_list" >isShuttingDown</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#listPathRes" class="function_list" >listPathRes</a>( path, extension ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#matchPath" class="function_list" >matchPath</a>( res ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#open" class="function_list" >open</a>( res, mode, encoding ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#publish" class="function_list" >publish</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#registerReadFileDescriptor" class="function_list" >registerReadFileDescriptor</a>( fileDescriptor, callback ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#registerWriteFileDescriptor" class="function_list" >registerWriteFileDescriptor</a>( fileDescriptor, callback ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#raycast" class="function_list" >raycast</a>( spaceID, layer, src, dst ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#reloadScript" class="function_list" >reloadScript</a>( fullReload ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#scriptLogType" class="function_list" >scriptLogType</a>( logType ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#setAppFlags" class="function_list" >setAppFlags</a>( flags ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#setSpaceData" class="function_list" >setSpaceData</a>( spaceID, key, value ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#time" class="function_list" >time</a>(  ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#urlopen" class="function_list" >urlopen</a>( url, callback, postData, headers ):</span>
</td></tr>

</table>

<h2><a href="#" onClick="obj=document.getElementById( 'callbacks' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Callback</a></h2>
<table id="callbacks" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr><td>
<span class="function_list">def <a href="#onCellAppData" class="function_list" >onCellAppData</a>( key, value ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onCellAppDataDel" class="function_list" >onCellAppDataDel</a>( key ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onGlobalData" class="function_list" >onGlobalData</a>( key, value ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onGlobalDataDel" class="function_list" >onGlobalDataDel</a>( key ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onInit" class="function_list" >onInit</a>( isReload ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onSpaceData" class="function_list" >onSpaceData</a>( spaceID, key, value ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onSpaceGeometryLoaded" class="function_list" >onSpaceGeometryLoaded</a>( spaceID, mapping ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onAllSpaceGeometryLoaded" class="function_list" >onAllSpaceGeometryLoaded</a>( spaceID, isBootstrap, mapping ):</span>
</td></tr>

<tr><td>
<span class="function_list">def <a href="#onReadyForLogin" class="function_list" >onReadyForLogin</a>( isBootstrap ):</span>
</td></tr>
</table>

<h2><a href="#" onClick="obj=document.getElementById( 'attributes' );vis = (obj.style.display == 'none') ? 'block' : 'none'; obj.style.display = vis; return false;" class="h2">Attributes</a></h2>
<table id="attributes" cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><a href="#LOG_TYPE_DBG" class="attribute_list" >LOG_TYPE_DBG</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_ERR" class="attribute_list" >LOG_TYPE_ERR</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_INFO" class="attribute_list" >LOG_TYPE_INFO</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_NORMAL" class="attribute_list" >LOG_TYPE_NORMAL</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#LOG_TYPE_WAR" class="attribute_list" >LOG_TYPE_WAR</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#NEXT_ONLY" class="attribute_list" >NEXT_ONLY</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#cellAppData" class="attribute_list" >cellAppData</a></td><td>&nbsp; </td></tr>

<tr valign=top><td><a href="#component" class="attribute_list" >component</a></td><td>&nbsp; Read-only <a href="STRING.html">string</a></td></tr>

<tr valign=top><td><a href="#entities" class="attribute_list" >entities</a></td><td>&nbsp; <a href="Entities.html">Entities</a>
</td></tr>

<tr valign=top><td><a href="#globalData" class="attribute_list" >globalData</a></td><td>&nbsp; GlobalDataClient</td></tr>

</table>

<hr>
<h2>Member functions documentation</h2>

<a name="addSpaceGeometryMapping"></a><p class="function_definition">
<span class="function_definition">def addSpaceGeometryMapping( <i>spaceID, mapper, path, shouldLoadOnServer, params</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Associate a geometric mapping of a given space. After the function is 
called, the server and client will load the corresponding geometry data.<br>
<br><br>
On the server, all geometry data is loaded from the given directory into 
the specified space. These data may be divided into many blocks. Different 
blocks are loaded asynchronously. The following callback methods are 
called when all the geometry data is loaded:
<pre>	def onAllSpaceGeometryLoaded( self, spaceID, mappingName ):
</pre>
<br>

The server only loads the geometric data of the scene for use by the 
navigation and collision functions. In addition to the geometric data, 
the client also loads data such as textures.
<br>
3D scenes currently use the data exported by the recastnavigation 
plugin-in by default. 2D scenes currently use the data exported by 
MapEditor by default.

<br><br>
There is a possibility that onAllSpaceGeometryLoaded() will not be 
invoked, that is, if multiple Cellapps call this method at the same time 
to add geometry to the same space, cellappmgr crashes.

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
uint32, ID of the space, specifies in which space to operate
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>mapper</i></span></td><td><span class="function_parameter_description">
Not yet implemented
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
Directory path containing geometry data
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>shouldLoadOnServer</i></span></td><td><span class="function_parameter_description">
Optional boolean parameter that specifies whether to load geometry on 
the server. Default is True.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>params</i></span></td><td><span class="function_parameter_description">
Optional PyDict parameter, specifies the navmesh used by different layers, for example:<br>
KBEngine.addSpaceGeometryMapping(self.spaceID, None, resPath, True, {0 : "srv_xinshoucun_1.navmesh", 1 : "srv_xinshoucun.navmesh"})
</span></td></tr>

</table>
</p>

<a name="addWatcher"></a><p class="function_definition">
<span class="function_definition">def addWatcher( <i>path, dataType, getFunction</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Interacts with the debug monitoring system to allow users to register 
a monitoring variable with the monitoring system.
<br><br>
Example:
<br>

<pre>
>>> def countPlayers( ):
>>>     i = 0
>>>     for e in KBEngine.entities.values():
>>>     	if e.__class__.__name__ == "Avatar":
>>>     		i += 1
>>>     return i
>>>
>>> <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#addWatcher>addWatcher</a>( "players", "UINT32", countPlayers )
</pre>
<br><br>
This function adds a watch variable under the "scripts/players" watch path. 
The function countPlayers is called when the watcher observes a change.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
The path to create a watcher.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dataType</i></span></td><td><span class="function_parameter_description">
The value type of the monitored variable. Reference: <a href=../../basetypes.html>Basic data types</a>
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>getFunction</i></span></td><td><span class="function_parameter_description">
This function is called when the observer retrieves the variable.
This function returns a value representing a watch variable without arguments.
</span></td></tr>

</table>
</p>



<a name="address"></a><p class="function_definition">
<span class="function_definition">def address( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Returns the address of the internal network interface.
</div>


<a name="MemoryStream"></a><p class="function_definition">
<span class="function_definition">def MemoryStream( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Return a new MemoryStream object.<br>
<br>
The MemoryStream object stores binary information. This type is provided 
to allow the user to easily serialize and deserialize the Python base types 
following the same KBEngine underlying serialization rules.<br>
<br><br>
For example, you can use this object to construct a network packet that 
KBEngine can parse.
<br><br>
Usage:
<pre>
>>> s = KBEngine.MemoryStream()
>>> s
>>> b''
>>> s.append("UINT32", 1)
>>> s.pop("UINT32")
>>> 1
</pre>
<br><br>
The types that MemoryStream currently supports are only basic data types. 
Reference: <a href=../../basetypes.html>Basic data types</a>
</div>


<a name="createEntity"></a><p class="function_definition">
<span class="function_definition">def createEntity( <i>entityType, spaceID, position, direction, params</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
createEntity creates a new entity in the specified space of the current 
process.
<br>
When calling this function you must specifiy the type, location, and direction 
of the entity to be created. Optionally, any attribute of the entity can 
be set with the params Python dictionary parameter. (the attributes are described in the entity's .def file).
<br><br>
Example:

<pre># Create an open Door entity in the same space as the "thing" entity
direction = ( 0, 0, thing.yaw )
properties = { "open":1 }
<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#createEntity>createEntity</a>( "Door", thing.space, thing.position, direction,
                       properties )
</pre>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>entityType</i></span></td><td><span class="function_parameter_description">
string, the name of the entity to create, declared in the <res><a href=../../keywords.html#entities.xml>/scripts/entities.xml</a>
file.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
int32, the ID of the space to place the entity
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>position</i></span></td><td><span class="function_parameter_description">
A sequence of 3 floats that specify the creation point of the new entity, 
in world coordinates.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>direction</i></span></td><td><span class="function_parameter_description">
A sequence of 3 floats that specify the initial orientation (roll, pitch, yaw) 
of the new entity in world coordinates.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>params</i></span></td><td><span class="function_parameter_description">
Optional parameters, a Python dictionary object. If a specified key is 
an <a href="../Classes/Entity.html">Entity</a> attribute, its value will 
be used to initialize the properties of the new <a href="../Classes/Entity.html">Entity</a>.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
The new <a href="../../keywords.html#cn_entity">Entity</a>.
</td></tr>
</table>
</p>



<a name="debugTracing"></a><p class="function_definition">
<span class="function_definition">def debugTracing( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Outputs the Python extension object counter that outputs KBEngine trace.<br>
Extended objects include: fixed dictionary, fixed array, Entity, EntityCall...<br>
If the counter is not zero when the server is shut down normally, it means 
that the leak already exists and the log will output an error message.<br><br>
ERROR cellapp [0x0000cd64] [2014-11-12 00:38:07,300] - PyGC::debugTracing(): FixedArray : leaked(128)<br>
ERROR cellapp [0x0000cd64] [2014-11-12 00:38:07,300] - PyGC::debugTracing(): EntityCall : leaked(8)
</div>


<a name="delSpaceData"></a><p class="function_definition">
<span class="function_definition">def delSpaceData( <i>spaceID, key </i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Deletes the space data of the specified key (if space is divided into 
multiple parts, it will be deleted synchronously).
<br>
The space data is set by the user via <a href=#setSpaceData>setSpaceData</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
int32, the ID of the space
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
string, a string keyword
</span></td></tr>
</table>
</p>



<a name="delWatcher"></a><p class="function_definition">
<span class="function_definition">def delWatcher( <i>path</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Interacts with the debug monitoring system, allowing users to delete 
watcher variables in the script.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
The path of the variable to delete.
</span></td></tr>

</table>
</p>



<a name="deregisterReadFileDescriptor"></a><p class="function_definition">
<span class="function_definition">def deregisterReadFileDescriptor( <i>fileDescriptor</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Deregisters the callback registered with <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#registerReadFileDescriptor>registerReadFileDescriptor</a>.
<br>
<br>
Example:<br>
<a href=http://www.kbengine.org/assets/other/py/Poller.py>http://www.kbengine.org/assets/other/py/Poller.py</a>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fileDescriptor</i></span></td><td><span class="function_parameter_description">
Socket descriptor/file descriptor
</span></td></tr>

</table>
</p>

<a name="deregisterWriteFileDescriptor"></a><p class="function_definition">
<span class="function_definition">def deregisterWriteFileDescriptor( <i>fileDescriptor</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Deregisters the callback registered with <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#registerWriteFileDescriptor>registerWriteFileDescriptor</a>.
<br>
<br>
Example:<br>
<a href=http://www.kbengine.org/assets/other/py/Poller.py>http://www.kbengine.org/assets/other/py/Poller.py</a>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fileDescriptor</i></span></td><td><span class="function_parameter_description">
Socket descriptor/file descriptor
</span></td></tr>

</table>
</p>



<a name="executeRawDatabaseCommand"></a><p class="function_definition">
<span class="function_definition">def executeRawDatabaseCommand( <i>command, callback, threadID, dbInterfaceName</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This script function executes a database command on the database, 
which will be directly parsed by the relevant database.
<br><br>
Please note that using this function to modify the entity data may not 
be effective because if the entity has been checked out, the modified 
entity data will still be archived by the entity and cause overwriting.<br>

This function is strongly not recommended for reading or modifying entity data.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>command</i></span></td><td><span class="function_parameter_description">
This database command will be different for different database configurations. 
For MySQL databases it will be an SQL query statement.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><p class="function_parameter_description">
  Optional parameter, callbacks object (for example, a function) with the 
  command's execution result. This callback has 4 parameters: result set, 
  number of rows affected, auto value, and error message.<br>
  Example:<br>
  def sqlcallback(result, rows, insertid, error):<br>
  &nbsp;&nbsp;&nbsp;&nbsp;print(result, rows, insertid, error) <br>
  <br>
  
As the above example shows, the result parameter corresponds to the 
"result set", and the result set parameter is a row. List. Each line is 
a list of strings containing field values.<br>
The command execution does not return a result set (for example, a DELETE 
command), or the result set is None if the command execution has an error. 
<br><br>
The rows parameter is the "number of rows affected", which is an integer 
indicating the number of rows affected by the command execution. This 
parameter is only relevant for commands that do not return results (such as DELETE). <br>
This parameter is None if there is a result set return or if there is an error in the command execution.
<br><br>
The insertid corresponds to a "long value", similar to the entity's 
databaseID. When successfully inserting data into a table with an auto 
long type field, it returns the data at the time of insertion. Assigned 
value. <br>
More information can be found in mysql's mysql_insert_id() method.
In addition, this parameter is only meaningful when the database type is 
mysql. 
<br><br>
error corresponds to the "error message", when the command execution error, 
this parameter is a string describing the error. This parameter is None 
when the command execution has not occurred.

<tr valign=top><td><span class="function_parameter_name"><i>threadID</i></span></td><td><span class="function_parameter_description">
int32, optional parameter, specifies a thread to process this command. 
Users can use this parameter to control the execution order of certain 
commands (dbmgr is multi-threaded). The default is not specified. If 
threadID is the ID of the entity, it will be added to the entity's archive 
queue and written by the thread one by one.<br>
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>dbInterfaceName</i></span></td><td><span class="function_parameter_description">
string, optional parameter, specified by a database interface, defaults 
to "default" interface. The database interface is defined by 
kbengine_defaults.xml->dbmgr->databaseInterfaces.
</span></td></tr>

</table>
</p>



<a name="genUUID64"></a><p class="function_definition">
<span class="function_definition">def genUUID64( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function generates a 64-bit unique ID.<br>
Note: This function is dependent on the 'gus' startup argument of the 
Cellapp service process. Please set the startup arguments to be unique.<br>
In addition, if gus exceeds 65535, this function can only remain unique 
on the current process.
<br>
<br>
Usage<br>
A unique item ID is generated on multiple service processes and there is 
no conflict when combined.<br>
A room ID is generated on multiple service processes and no uniqueness 
verification is required.<br>
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
64-bit integer
</td></tr>
</table>
</p>

<a name="getResFullPath"></a><p class="function_definition">
<span class="function_definition">def getResFullPath( <i>res</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get the absolute path of the resource.<br>
Note: Resoures must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, if there is an absolute path to return the resource, otherwise it returns null.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
string, the absolute path to the resource.
</td></tr>
</table>
</p>



<a name="getSpaceData"></a><p class="function_definition">
<span class="function_definition">def getSpaceData( <i>spaceID, key </i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get the space data of the specified key.
<br>
The space data is set by the user via <a href=#setSpaceData>setSpaceData</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
int32, the ID of the space
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
string, a string keyword
</span></td></tr>
</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
string, string data for the given key
</td></tr>
</table>
</p>


<a name="getSpaceGeometryMapping"></a><p class="function_definition">
<span class="function_definition">def getSpaceGeometryMapping( <i>spaceID</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Returns the geometry map name of a specified space.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
The ID of the space to be queried
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
string, the name of the geometry map.
</td></tr>
</table>
</p>




<a name="getWatcher"></a><p class="function_definition">
<span class="function_definition">def getWatcher( <i>path</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Gets the value of a watch variable from the KBEngine debug system.
<br>
<br>
Example: In the baseapp1 Python console, enter:<br>
>>>KBEngine.getWatcher("/root/stats/runningTime")
<br>
12673648533
<br>
<br>
>>>KBEngine.getWatcher("/root/scripts/players")
<br>
32133
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
string, the absolute path of the variable including the variable name 
(can be viewed on the GUIConsole watcher page).
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
The value of the variable.
</td></tr>
</table>
</p>


<a name="getWatcherDir"></a><p class="function_definition">
<span class="function_definition">def getWatcherDir( <i>path</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get a list of elements (directories, variable names) under the watch 
directory from the KBEngine debugging system.
<br>
<br>
Example: In baseapp1 Python console, enter:<br>
>>>KBEngine.getWatcher("/root")
<br>
('stats', 'objectPools', 'network', 'syspaths', 'ThreadPool', 'cprofiles', 'scripts', 'numProxices', 'componentID', 'componentType', 'uid', 'numClients', 'globalOrder', 'username', 'load', 'gametime', 'entitiesSize', 'groupOrder')
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>path</i></span></td><td><span class="function_parameter_description">
string, the absolute path of the variable including the variable name 
(can be viewed on the GUIConsole watcher page).
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
The list of elements (directory, variable name) under the Watch directory.
</td></tr>
</table>
</p>



<a name="getAppFlags"></a><p class="function_definition">
<span class="function_definition">def getAppFlags( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get the flags of the current engine APP, Reference:<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#setAppFlags>setAppFlags</a>��
<br>
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
KBEngine.APP_FLAGS_*
</td></tr>
</table>
</p>




<a name="hasRes"></a><p class="function_definition">
<span class="function_definition">def hasRes( <i>res</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Use this interface to determine if a relative path exists.<br>
Note: Resources must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
<br>
<br>
Example:
<br>
<br>
>>>KBEngine.hasRes("<a href=../../keywords.html#entities.xml>scripts/entities.xml</a>")
<br>
True
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path of the resource
</span></td></tr>
</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
BOOL, if it exists return True, otherwise False.
</td></tr>
</table>
</p>


<a name="isShuttingDown"></a><p class="function_definition">
<span class="function_definition">def isShuttingDown( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Returns whether the server is shutting down. After the onBaseAppShuttingDown 
callback function is called, this function returns True.
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
BOOL, if the server is shutting down True, otherwise False.
</td></tr>
</table>
</p>



<a name="listPathRes"></a><p class="function_definition">
<span class="function_definition">def listPathRes( <i>path, extension</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Get a list of resources in a resource directory<br>
Note: Resources must be accesible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
<br>
<br>
Example:
<br>
<br>
>>>KBEngine.listPathRes("scripts/cell/interfaces")
<br>
('/home/kbe/kbengine/demo/res/scripts/cell/interfaces/AI.py', '/home/kbe/kbengine/demo/res/scripts/cell/interfaces/New Text Document.txt')
<br><br>
>>>KBEngine.listPathRes("scripts/cell/interfaces", "txt")
<br>
('/home/kbe/kbengine/demo/res/scripts/cell/interfaces/New Text Document.txt')
<br><br>
>>>KBEngine.listPathRes("scripts/cell/interfaces", "txt|py")
<br>
('/home/kbe/kbengine/demo/res/scripts/cell/interfaces/AI.py', '/home/kbe/kbengine/demo/res/scripts/cell/interfaces/New Text Document.txt')
<br><br>
>>>KBEngine.listPathRes("scripts/cell/interfaces", ("txt", "py"))
<br>
('/home/kbe/kbengine/demo/res/scripts/cell/interfaces/AI.py', '/home/kbe/kbengine/demo/res/scripts/cell/interfaces/New Text Document.txt')
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path of the resource.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>extension</i></span></td><td><span class="function_parameter_description">
string, optional parameter, file extension.
</span></td></tr>
</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
Tuple, resource list.
</td></tr>
</table>
</p>



<a name="matchPath"></a><p class="function_definition">
<span class="function_definition">def matchPath( <i>res</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Use the relative path of the resource to get its absolute path.<br>
Note: Resources must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
<br>
<br>
Example:
<br>
<br>
>>>KBEngine.matchPath("scripts/entities.xml")<br>
'/home/kbe/kbengine/demo/res/scripts/entities.xml'
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path to the resource (including the resource name)
</span></td></tr>
</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
string, the absolute path of the resource.
</td></tr>
</table>
</p>



<a name="open"></a><p class="function_definition">
<span class="function_definition">def open( <i>res, mode, encoding</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Use this interface to open resources using relative paths.
Note: Resources must be accessible under <a href=../../keywords.html#KBE_RES_PATH>KBE_RES_PATH</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>res</i></span></td><td><span class="function_parameter_description">
string, the relative path of the resource.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>mode</i></span></td><td><span class="function_parameter_description">
string, optional parameter, the default is 'r', file operation mode:<br>
r Open in only read mode,<br>
w Open in write mode, <br>
a Open in append mode (Start from EOF, create new file if necessary) <br>
r+ Open <br>
w+ in read/write mode Open in read/write mode (see w) <br>
a+ Open in read/write mode (See a) <br>
rb Opens <br>
wb in binary read mode Opens in binary write mode (see w) <br>
ab Opens in binary append mode (see a) <br>
rb+ Opens in binary read and write mode (see r+) <br>
wb+ Opens in binary read and write mode (see w+ ) <br>
ab+ Open in binary read/write mode (see a+)
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>encoding</i></span></td><td><span class="function_parameter_description">
string, optional parameter, the name of the encoding used to decode or encode the file, the default encoding is platform dependent.
</span></td></tr>

</table>
</p>

<a name="publish"></a><p class="function_definition">
<span class="function_definition">def publish( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This interface returns the current server release mode.
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
int8, 0: debug, 1: release, others can be customized.
</td></tr>
</table>
</p>



<a name="raycast"></a><p class="function_definition">
<span class="function_definition">def raycast( <i>spaceID, layer, src, dst</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
In the specified layer of the specified space, a ray is emitted from the 
source coordinates to the destination coordinates, and the collided 
coordinate point is returned.
<br><br>
Note: Space must load geometry using <a href=#addSpaceGeometryMapping>addSpaceGeometryMapping</a>.
<br><br>
Below is an example:
<br><br>

<pre>	>>> KBEngine.raycast( spaceID, entity.layer, (0, 10, 0), (0,-10,0) )
	((0.0000, 0.0000, 0.0000), ( (0.0000, 0.0000, 0.0000),
	(4.0000, 0.0000, 0.0000), (4.0000, 0.0000, 4.0000)), 0)
</pre>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
int32, space ID
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>layer</i></span></td><td><span class="function_parameter_description">
int8, geometric layer. A space can load multiple navmesh data at the 
same time. Different navmesh can be in different layers. Different 
layers can be abstracted into the ground, the water surface and so on.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>list, list of coordinate points collided
</td></tr>
</table>
</p>



<a name="registerReadFileDescriptor"></a><p class="function_definition">
<span class="function_definition">def registerReadFileDescriptor( <i>fileDescriptor, callback</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Registers a callback function that is called when the file descriptor is readable.
<br>
<br>
Example:<br>
<a href=http://www.kbengine.org/assets/other/py/Poller.py>http://www.kbengine.org/assets/other/py/Poller.py</a>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fileDescriptor</i></span></td><td><span class="function_parameter_description">
Socket descriptor/file descriptor
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
A callback function with the socket descriptor/file descriptor as its only 
parameter.
</span></td></tr>

</table>
</p>

<a name="registerWriteFileDescriptor"></a><p class="function_definition">
<span class="function_definition">
def registerWriteFileDescriptor( <i>fileDescriptor, callback</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Registers a callback function that is called when the socket descriptor/file descriptor is writable. 
<br>
<br>
Example:<br>
<a href=http://www.kbengine.org/assets/other/py/Poller.py>http://www.kbengine.org/assets/other/py/Poller.py</a>
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fileDescriptor</i></span></td><td><span class="function_parameter_description">
Socket descriptor/file descriptor
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td><td><span class="function_parameter_description">
A callback function with the socket descriptor/file descriptor as its only parameter.
</span></td></tr>

</table>
</p>



<a name="reloadScript"></a><p class="function_definition">
<span class="function_definition">def reloadScript( <i>fullReload</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Reloads Python modules related to entity and custom data types. 
The current entity class is set to the newly loaded class. 
This method should only be used for development mode and not for 
product mode. The following points should be noted: 
<br><br>
1) The overloaded script can only be executed on <a href="../index.html">Cellapp</a>.
The user should ensure that all server components are loaded.
<br><br>
2) The custom type should ensure that the objects already instantiated 
in memory are updated after the script is reloaded. Here is an example: 
<br><br>

<pre>for e in <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#entities>entities</a>.values():
   if type( e ) is Avatar.Avatar:
      e.customData.__class__ = CustomClass
</pre>
When this method completes <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onInit>onInit</a>( True ) 
is called.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>fullReload</i></span></td><td><span class="function_parameter_description">
Optional boolean parameter that specifies whether to reload entity 
definitions at the same time. If this parameter is False, the entity 
definition will not be reloaded. The default is True.
</span></td></tr>

</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>True if the reload succeeds, False otherwise.
</td></tr>
</table>
</p>



<a name="scriptLogType"></a><p class="function_definition">
<span class="function_definition">def scriptLogType( <i>logType</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Set the type of information output by the current Python.print (Reference: KBEngine.LOG_TYPE_*).
</div>



<a name="setAppFlags"></a><p class="function_definition">
<span class="function_definition">def setAppFlags( <i>flags</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Set the flags of the current engine APP.
<br>
<br>
KBEngine.APP_FLAGS_NONE // Default (not set)<br>
KBEngine.APP_FLAGS_NOT_PARTCIPATING_LOAD_BALANCING // Do not participate in load balancing<br>
<br>
Example:<br>
KBEngine.setAppFlags(KBEngine.APP_FLAGS_NOT_PARTCIPATING_LOAD_BALANCING | KBEngine.APP_FLAGS_*)
</div>



<a name="setSpaceData"></a><p class="function_definition">
<span class="function_definition">def setSpaceData( <i>spaceID, key, value </i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Sets the space data for the specified key.
<br>
The space data can be obtained via <a href=#getSpaceData>getSpaceData</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
int32, the ID of the space.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
string, a string keyword
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>value</i></span></td><td><span class="function_parameter_description">
string, the string value.
</span></td></tr>
</table>

</table>
</p>


<a name="time"></a><p class="function_definition">
<span class="function_definition">def time( <i></i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This method returns the current game time (number of cycles).
</div>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>
uint32, the current time of the game. This refers to the number of cycles. 
The period is affected by the frequency. The frequency is determined by 
the configuration file <a href=../../keywords.html#kbengine.xml>kbengine.xml</a> or <a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>-> gameUpdateHertz.
</td></tr>
</table>
</p>




<a name="urlopen"></a><p class="function_definition">
<span class="function_definition">def urlopen( <i>url, callback, postData, headers</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This script function is providing an external HTTP/HTTPS asynchronous request.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>url</i></span></td><td><span class="function_parameter_description">
A valid HTTP/HTTPS URL.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>callback</i></span></td>
<td><p class="function_parameter_description">
Optional parameter with a callback object (for example, a function) that requests execution results. This callback takes five parameters: the HTTP request return code (eg: 200), 
the returned content, the returned HTTP protocol header, whether it succeeded, and the requested URL.
<br>
Example:<br>
def 
onHttpCallback(httpcode, data, headers, success, url):<br>
&nbsp;&nbsp;&nbsp;&nbsp;print(httpcode, data, headers, success, url)  <br>
<br>
As the above example shows:
<br><p class="function_parameter_description"></p>httpcode:The parameter corresponds to the &quot;HTTP request return code&quot;, is an integer.
<p class="function_parameter_description"></p>data:The parameter is &ldquo; returned content & rdquo;, it is a string.
</p>
<p class="function_parameter_description">headers:The parameter is the HTTP protocol header returned by the server, such as:{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
<p class="function_parameter_description">success:Whether the execution is successful or not, when the request execution has an error, it is False, and the error information can be further judged by httpcode.
</p>
<p class="function_parameter_description"></p>url:Is the URL used by the request.
</p>
</td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>postData</i></span></td><td><span class="function_parameter_description">
Optional parameter, the default is GET mode request server. If you need POST mode, please provide the content that needs POST. The engine will automatically request the server using POST, is an bytes.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>headers</i></span></td><td><span class="function_parameter_description">
Optional parameter, HTTP header used when requesting, such as：{"Content-Type": "application/x-www-form-urlencoded"}, is an dict.
</span></td></tr>

</table>
</p>

  


<hr>
<h2>Callback functions documentation</h2>

<a name="onCellAppData"></a><p class="function_definition">
<span class="function_definition">def onCellAppData( <i>key, value</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when KBEngine.cellAppData changes.
<br>Note: This callback interface must be implemented in the portal 
module ( <a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile ).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
The key of the changed data.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>value</i></span></td><td><span class="function_parameter_description">
The value of the changed data.
</span></td></tr>

</table>
</p>

<a name="onCellAppDataDel"></a><p class="function_definition">
<span class="function_definition">def onCellAppDataDel( <i>key</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when KBEngine.cellAppData is deleted.
<br>Note: This callback interface must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
Deleted data key.
</span></td></tr>

</table>
</p>

<a name="onGlobalData"></a><p class="function_definition">
<span class="function_definition">def onGlobalData( <i>key, value</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when KBEngine.globalData changes.
<br>Note: This callback interface must be implemented in the portal moodule (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
The key of the changed data.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>value</i></span></td><td><span class="function_parameter_description">
The value of the changed data.
</span></td></tr>

</table>
</p>

<a name="onGlobalDataDel"></a><p class="function_definition">
<span class="function_definition">def onGlobalDataDel( <i>key</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This function is called back when KBEngine.globalData is deleted.
<br>Note: This callback interface must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
Deleted data key.
</span></td></tr>

</table>
</p>

<a name="onInit"></a><p class="function_definition">
<span class="function_definition">def onInit( <i>isReload</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
This interface is called after all scripts have been initialized since 
the engine started.
<br>Note: This callback interface must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>isReload</i></span></td><td><span class="function_parameter_description">
Bool, whether it was triggered after reloading the loading the script.
</span></td></tr>

</table>
</p>

<a name="onSpaceData"></a><p class="function_definition">
<span class="function_definition">def onSpaceData( <i>spaceID, key, value</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
Called when there is a change in the space data.<br>
The space data is set by the user via <a href=#setSpaceData>setSpaceData</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
The ID of the space.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>key</i></span></td><td><span class="function_parameter_description">
The key of the changed data.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>value</i></span></td><td><span class="function_parameter_description">
The value of the changed data.
</span></td></tr>

</table>
</p>

</table>
</p>


<a name="onSpaceGeometryLoaded"></a><p class="function_definition">
<span class="function_definition">def onSpaceGeometryLoaded( <i>spaceID, mapping</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
The space required by the grid collision data is loaded.<br>
Set by user through <a href=#addSpaceGeometryMapping>addSpaceGeometryMapping</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
The ID of the space.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>mapping</i></span></td><td><span class="function_parameter_description">
The map value of the grid collision data.
</span></td></tr>

</table>
</p>

</table>
</p>



<a name="onAllSpaceGeometryLoaded"></a><p class="function_definition">
<span class="function_definition">def onAllSpaceGeometryLoaded( <i>spaceID, isBootstrap, mapping</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
The space required for grid collision and other data is completely loaded.<br>
Set by user through <a href=#addSpaceGeometryMapping>addSpaceGeometryMapping</a>.
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>spaceID</i></span></td><td><span class="function_parameter_description">
The ID of the space.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>isBootstrap</i></span></td><td><span class="function_parameter_description">
If a space is partitioned by multiple cells, isBootstrap describes 
whether it is the originating cell of the loading request.
</span></td></tr>

<tr valign=top><td><span class="function_parameter_name"><i>mapping</i></span></td><td><span class="function_parameter_description">
The map value of grid collision data.
</span></td></tr>

</table>
</p>

</table>
</p>

<a name="onReadyForLogin"></a><p class="function_definition">
<span class="function_definition">def onReadyForLogin( <i>isBootstrap</i> ):</span>
</p>

<div class="function_description">
<b>Function description:</b><br><br>
When the engine is started and initialized, it will always call this function 
to ask whether the script layer is ready. If the script layer is ready, 
loginapp allows the client to log in.
<br>Note: This callback function must be implemented in the portal module (<a href=../../keywords.html#kbengine_defaults.xml>kbengine_defaults.xml</a>->entryScriptFile).
</div>

<p>
<span class="function_parameter">parameters:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">

<tr valign=top><td><span class="function_parameter_name"><i>isBootstrap</i></span></td><td><span class="function_parameter_description">
bool, True if this is the first <a href="../index.html">Cellapp</a> started.
</span></td></tr>



</table>
</p>

<p>
<span class="function_return">returns:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td>If the return value is greater than or equal to 1.0, the script 
layer is ready; otherwise, return a value from 0 to less than 1.0.
</td></tr>
</table>
</p>


<hr>
<h2>Attribute documentation</h2>

<a name="LOG_TYPE_DBG"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_DBG</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is debug.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="LOG_TYPE_ERR"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_ERR</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is error.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="LOG_TYPE_INFO"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_INFO</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is general information.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="LOG_TYPE_NORMAL"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_NORMAL</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is normal.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="LOG_TYPE_WAR"></a><p class="attribute_definition">
<span class="attribute_definition">LOG_TYPE_WAR</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
The log output type is warning.<br>
Set by <a href=#scriptLogType>scriptLogType</a>.
</div>

<a name="NEXT_ONLY"></a><p class="attribute_definition">
<span class="attribute_definition">NEXT_ONLY</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This constant is currently unused in Cellap.
</div>

<a name="cellAppData"></a><p class="attribute_definition">
<span class="attribute_definition">cellAppData</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This property contains a dictionary-like object that is automatically 
synchronized across all CellApps. When a value in the dictionary is 
modified, this change is broadcast to all Cellapps.

<br><br>
Example:

<pre><a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#cellAppData>cellAppData</a>[ "hello" ] = "there"
</pre>
<br><br>
The rest of Cellap can access the following:

<pre>print <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#cellAppData>cellAppData</a>[ "hello" ]
</pre>
<br><br>
Keys and values can be of any type, but these types must be encapsulated 
and unpacked on all target components.
<br><br>
When a value is changed or deleted, a callback function is called on all 
components. See: <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onCellAppData>onCellAppData</a> and <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onDelCellAppData>onDelCellAppData</a>.
<br><br>
Note: Only the top-level value will be broadcast. If you have a value 
(such as a list) that changes the internal value (such as just changing 
a number), this information will not be broadcast.
<br><br>
Do not do the following:

<pre><a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#cellAppData>cellAppData</a>[ "list" ] = [1, 2, 3]
<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#cellAppData>cellAppData</a>[ "list" ][1] = 7
</pre>
This will cause the local access to read [1, 7, 3] and the remote [1, 2, 3]
</div>

<a name="component"></a><p class="attribute_definition">
<span class="attribute_definition">component</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This is the component that is running in the current Python environment. (So far) Possible values are 'cellapp', 'baseapp', 'client', 'dbmgr', 'bots' and 'editor'.
</div>

<a name="entities"></a><p class="attribute_definition">
<span class="attribute_definition">entities</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
entities is a dictinary object that contains all entities in the current 
process, including <a href=../../keywords.html#ghost>ghost</a> entities.<br>
<br>
Debugging leaked entities: (instances that call destroy without releasing 
memory, usually as a result of the reference not being released)<br>
<pre>
>>> KBEngine.entities.garbages.items()
[(1025, Avatar object at 0x7f92431ceae8.)]
<br>
>>> e = _[0][1]
>>> import gc
>>> gc.get_referents(e)
[{'spacesIsOk': True, 'bootstrapIdx': 1}, <class 'Avatar.Avatar'>]
</pre>
<br>
Debugging a leaked KBEngine-encapsulated Python object:<br>
<a href=#debugTracing>KBEngine.debugTracing</a>
</div>

<p>
<span class="attribute_type">Types:</span>
<table border=0 cellpadding=0 cellspacing=3 style="margin-left: 20px;">
<tr><td><a href="../Classes/Entity.html">Entities</a>
</td></tr>
</table>
</p>

<a name="globalData"></a><p class="attribute_definition">
<span class="attribute_definition">globalData</span>
</p>

<div class="attribute_description">
<b>Description:</b><br><br>
This attribute contains a dictionary-like object that is automatically 
copied between all BaseApps and CellApps. When a value in a dictionary is 
modified, this change is broadcast to all BaseApps and CellApps. 
CellAppMgr solves completion conditions and ensures the authority of 
information replication.
<br><br>
Example:

<pre><a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#globalData>globalData</a>[ "hello" ] = "there"
</pre>
<br><br>
The rest of <a href="../index.html">Cellapp</a> or <a href="../index.html"><a href="../../baseapp/index.html">Baseapp</a></a>
can access the following:

<pre>print <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#globalData>globalData</a>[ "hello" ]
</pre>
<br><br>
Keys and values can be of any type, but these types must be encapsulated and unpacked on all target components. 
<br><br>

When a value is changed or deleted, a callback function is called on all components.
See: <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onGlobalData>onGlobalData</a> and <a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#onGlobalDataDel>onGlobalDataDel</a>.
<br><br>
Note: Only the top-level value will be broadcast. If you have a volatile value (such as a list) that changes the internal value (such as just changing a number), this information will not be broadcast.
<br><br>
Do not do the following:

<pre><a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#globalData>globalData</a>[ "list" ] = [1, 2, 3]
<a href="KBEngine.html">KBEngine</a>.<a href=KBEngine.html#globalData>globalData</a>[ "list" ][1] = 7
</pre>
This will cause the local access to read [1, 7, 3] and the remote [1, 2, 3]
</div>

<hr>
<p class="copyrightFooter">Copyright KBEngine</p>
</body>
</html>
